//
//  IndexViewController.m
//  lcf-newproject
//
//  Created by yangyang on 14-11-19.
//  Copyright (c) 2014年 yang. All rights reserved.
//

#import "IndexViewController.h"
#import "LCFNetWorkRequest.h"
#import "IndexProjectCell.h"
#import "CustomImageScrollView.h"
#import "CustomProgressView.h"
#import "ProjectDetailViewController.h"
@interface IndexViewController ()
@property (nonatomic,strong)UITableView * tableView;
@property (nonatomic,strong)NSMutableArray * dataArray;
@property (nonatomic,strong)UIView * topView;

@end

@implementation IndexViewController



#pragma mark - UIViewController生命周期
-(void)viewDidLoad{
    [super viewDidLoad];
    [self uiConfig];
    //[self prepareData];
}


-(void)uiConfig{
    _dataArray = [[NSMutableArray alloc]init];
    _tableView = [self creataTableViewWithFrame:CGRectMake(0, 0, __MainScreen_Width, __MainScreen_Height-__TabBar_Height) withTableViewStyle:UITableViewStylePlain];
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    _tableView.showsVerticalScrollIndicator = NO;
    [_tableView setSeparatorInset:UIEdgeInsetsZero];
    [self.view addSubview:_tableView];
#pragma mark - 以后要修改的
    [self setNavigationRightBarWithTitle:nil withNormalImageName:@"message.png" withSelectedImageName:nil withAction:@selector(messageBtnClick:)];
}

-(void)prepareData{
    
    [[LCFNetWorkRequest shareRequestManager]sendAsynchronousRequestDataWithUrl:@"www.baidu.com" parameters:nil requestMethod:LCFRequestGetMethod completionHandle:^(ResponseItem * item) {
        
    } failedHandler:^(NSError *error) {
        
    }];
}
//创建scrollView
-(UIView *)createScrollView{
    NSArray *imageNameArray = @[@"test1",@"test2",@"test0"];
    NSDictionary * dict = [NSDictionary dictionaryWithObject:imageNameArray forKey:@"imageUrl"];
    CustomImageScrollView * scrollView = [[CustomImageScrollView alloc]initWithImageData:dict];
    scrollView.viewframe = CGRectMake(0, 0, __MainScreen_Width,ScrollViewHeight);
    return [scrollView createImageScrollView];
}



#pragma mark - UITableViewDeleagte
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return ScrollViewHeight;
    }
    return ProjectCellHeight;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row!=0){
    ProjectDetailViewController * detail = [[ProjectDetailViewController alloc]init];
    [self.navigationController pushViewController:detail animated:YES];
    }
}

#pragma mark - UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 25;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        static NSString * cellIde = @"scrollViewCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIde];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIde];
           _topView = [self createScrollView];
        }
        [cell.contentView addSubview:_topView];
        return cell;
    }else{
        static NSString * cellIde = @"IndexProjectCell";
        IndexProjectCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIde];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle]loadNibNamed:@"IndexProjectCell" owner:self options:nil]lastObject];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.tradeTypeImageView.image = [UIImage imageNamed:@"xiao.png"];
        cell.projectNameLabel.text = @"客运公司运营车辆";
        cell.earningLabel.text = @"15";
        cell.financinglimitLabel.text = @"1000";
        cell.monthLimitLabel.text = @"12";
        cell.bondingCompanyNameLabel.text = @"北京同益达担保有限公司";
        cell.repayTimeLabel.text = @"2015-10-10";
        [cell createProgressView:0.89];
        
        return cell;
    }
    return nil;
}


-(void)messageBtnClick:(UIButton *)btn{
    NSLog(@"message：以后转为view");
}



@end
